function Food(el){
    this.el = el
    this.len = 20
    this.foodObj=null
    this.foodx =0
    this.foodY =0
    this.init()
}
Food.prototype.init = function(){
    this.food()
    
}
Food.prototype.food = function(){
    let divObj= document.createElement('div')
    divObj.style.width = this.len +'px'
    divObj.style.height = this.len +'px'
    divObj.style.background = 'green'
    divObj.style.position ='absolute'
    this.foodObj = divObj
    
    this.el.appendChild(divObj)
    this.suijifood()
}  
Food.prototype.suijifood = function(){
    //获取box的宽
    let foodwinum = this.el.clientWidth/this.len-1
    let foodhenum = this.el.clientHeight/this.len-1
    //随机个数*this.len
    this.foodx = Math.floor(Math.random()*(foodwinum-0+1)+0)*this.len
    this.foodY = Math.floor(Math.random()*(foodhenum-0+1)+0)*this.len

    this.foodObj.style.left = this.foodx +'px'
    this.foodObj.style.top = this.foodY +'px'
} 